package com.sixth.controller;

import com.sixth.bean.MarketNoticeAdmin;
import com.sixth.bean.bo.AdminProfileBcatnoticeBo;
import com.sixth.bean.bo.AdminProfilePasswordBo;
import com.sixth.bean.common.BasePageInfo;
import com.sixth.bean.common.BaseRespVo;
import com.sixth.bean.common.BaseResultVo;
import com.sixth.constant.Constant;
import com.sixth.service.AdminProfileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName AdminProfileController
 * @Description TODO
 * @Author XiaoWJ
 * @Date 2022/9/9 19:46
 **/
@RestController
@RequestMapping("admin/profile")
public class AdminProfileController {

    @Autowired
    AdminProfileService adminProfileService;
    
    
    /** 
     * 修改当前管理员的密码
     * @Param  AdminProfilePasswordBo
     * @Return BaseResultVo
     * @author XiaoWJ
     * @date   2022/9/13 10:07
     */
    
    //@RequiresPermissions(value = {"admin:profile:password"},logical = Logical.OR)
    @RequestMapping("password")
    public BaseResultVo password(@RequestBody AdminProfilePasswordBo adminProfilePasswordBo){

        if(adminProfilePasswordBo.getNewPassword().equals(adminProfilePasswordBo.getOldPassword())){
            return BaseResultVo.error("密码未修改！");

        }
        int code = adminProfileService.password(adminProfilePasswordBo);

        if(code == Constant.NON){
            return BaseResultVo.error("旧密码错误");
        }
        return BaseResultVo.ok("修改密码成功！");
    }

    @RequestMapping("nnotice")
    public BaseResultVo nnotice(){

        return BaseResultVo.ok("修改密码成功！");
    }

    
    /** 
     * @Param
     * @Return 
     * @author XiaoWJ
     * @date   2022/9/13 10:07
     */
    
    @RequestMapping("lsnotice")
    public BaseRespVo lsnotice(BasePageInfo basePageInfo, String type, String title){

        Object result = adminProfileService.lsnotice(basePageInfo,type,title);

        return BaseRespVo.ok(result);
    }

    /**
     * @Param
     * @Return
     * @author XiaoWJ
     * @date   2022/9/13 10:07
     */

    @RequestMapping("catnotice")
    public BaseRespVo catnotice(@RequestBody MarketNoticeAdmin marketNoticeAdmin){


       int code = adminProfileService.catnotice(marketNoticeAdmin);

       if (code == Constant.OK ) {
            return BaseRespVo.ok();
       }
       return BaseRespVo.error("修改失败");
    }

    /**
     * @Param
     * @Return
     * @author XiaoWJ
     * @date   2022/9/13 10:07
     */

    @RequestMapping("bcatnotice")
    public BaseRespVo bcatnotice(@RequestBody AdminProfileBcatnoticeBo adminProfileBcatnoticeBo){


        int code = adminProfileService.bcatnotice(adminProfileBcatnoticeBo.getIds());

        if (code == Constant.OK ) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.error("修改失败");
    }

    /**
            * @Param
     * @Return
     * @author XiaoWJ
     * @date   2022/9/13 10:07
            */

    @RequestMapping("brmnotice")
    public BaseRespVo brmnotice(@RequestBody AdminProfileBcatnoticeBo adminProfileBcatnoticeBo){


        int code = adminProfileService.brmnotice(adminProfileBcatnoticeBo.getIds());

        if (code == Constant.OK ) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.error("修改失败");
    }


}
